package org.newlifecac;

import java.io.*;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;


import android.R.integer;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;

public class DBService
{
	@SuppressWarnings("unused")
	private Context context;
	private DBOpenHelper dbHelper;

	public DBService(Context context)
	{
		dbHelper = new DBOpenHelper(context);
	}

	public List<States> getStatesById(String Id)
	{
		String str = "'%" + Id + "%'";
		List<States> list = new ArrayList<States>();
		SQLiteDatabase db = dbHelper.getReadableDatabase();
		Cursor cs = db.rawQuery("select * from t_states where state_id like " + str, null);
		if (cs == null)
			return null;
		while (cs.moveToNext())
		{
			States item = new States();
			item.setState_id(cs.getString(cs.getColumnIndex("state_id")));
			item.setState_name(cs.getString(cs.getColumnIndex("state_name")));
			list.add(item);
		}
		cs.close();
		return list;
	}
	
	public List<States> getStates()
	{
		List<States> list = new ArrayList<States>();
		String sql = "select * from t_states";
		SQLiteDatabase db = dbHelper.getWritableDatabase();
		Cursor cursor = db.rawQuery(sql, null);
		if (cursor == null)
			return null;
		while (cursor.moveToNext())
		{
			States item = new States();
			item.setState_id(cursor.getString(0));
			item.setState_name(cursor.getString(1));
			list.add(item);
		}
		cursor.close();
		return list;
	}

	public void closeDB()
	{
		dbHelper.close();
	}
}
